package com.platform.modules.mall.activity.rule;

import com.platform.common.exception.BusinessException;
import com.platform.modules.mall.entity.MallGoodsToActivityEntity;

import java.util.Iterator;
import java.util.List;

public abstract class RuleAbstract {

    /**
     * 该活动中关联的所有商品
     */
    protected List<MallGoodsToActivityEntity> entityList;

    protected RuleAbstract(List<MallGoodsToActivityEntity> list){
        if (list==null||list.size()==0){
            throw new BusinessException("关联商品不能为空");
        }
        this.entityList=list;
    }

    public void delEntity(MallGoodsToActivityEntity entity){
        Iterator<MallGoodsToActivityEntity> iterator = entityList.iterator();
        while (iterator.hasNext()){
            MallGoodsToActivityEntity goods = iterator.next();
            if (goods.getId().equals(entity.getId())){
                iterator.remove();
            }
        }
    }

    public abstract MallGoodsToActivityEntity getEntity();

}
